package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	/**
	 * summary = "第一个接口: 查询1 2 3 分类"
	 * @return
	 */
	@Operation(summary = "①查询1 2 3 分类")
	@GetMapping("/category/getBaseCategoryList")
	public Result<List<JSONObject>> getBaseCategoryList(){

		List<JSONObject> data = 	baseCategoryService.getBaseCategoryList();

		return Result.ok(data);
	}

	/**
	 * 根据一级分类Id获取分类属性以及属性值（标签名，标签值）
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类查询专辑属性值信息")
	@GetMapping("/category/findAttribute/{category1Id}")
	public Result<List<BaseAttribute>> findAttributeByCategory1Id(@PathVariable Long category1Id){
		List<BaseAttribute>   attributeList  =  	baseCategoryService.findAttributeByCategory1Id(category1Id);
		return Result.ok(attributeList);
	}

	/**
	 * 该接口是 为了将该分类信息加入到索引库中
	 * @param category3Id 三级分类id
	 * @return 分类信息 包含 category1Id category2Id category3Id 将这三个放入到索引库albumifno
	 */
	@Operation(summary = "根据三级分类查询 分类信息")
	@GetMapping("/category/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getBaseCategoryViewByCategory3Id(@PathVariable Long category3Id){

		BaseCategoryView baseCategoryView  =	baseCategoryService.getBaseCategoryViewByCategory3Id(category3Id);

		return Result.ok(baseCategoryView);

	}

	/**
	 * 根据一集分类查询一级分类下包含的三级分类列表
	 * @param category1Id 一级分类
	 * @return 返回三级分类列表
	 */
	@Operation(summary = "根据一级分类ID查询该一级分类下包含所有三级分类列表")
	@GetMapping("/category/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> getTop7BaseCategory3(@PathVariable Long category1Id) {
		List<BaseCategory3> list = baseCategoryService.getTop7BaseCategory3(category1Id);
		return Result.ok(list);
	}


	@Operation(summary = "根据一级分类ID查询当前分类包含所有二级分类以及二级分类下三级分类列表")
	@GetMapping("/category/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getCategoryListByCategory1Id(@PathVariable Long category1Id) {
		JSONObject jsonObject = baseCategoryService.getCategoryListByCategory1Id(category1Id);
		return Result.ok(jsonObject);
	}

	/**
	 * 热度排行下的一级分类
	 * @return
	 */
	@Operation(summary = "热度排行 1.获取所有的一级分类列表")
	@GetMapping("/category/findAllCategory1")
	public Result<List<BaseCategory1>> getBaseCategory1IdList(){
		return Result.ok(baseCategoryService.list());
	}
}

